home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4882 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  63.3 KB

  1. Path: news.synopsys.com!jbuck
  2. From: jbuck@synopsys.com (Joe Buck)
  3. Newsgroups: gnu.g++.help,comp.lang.c++,news.answers,comp.answers
  4. Subject: FAQ for g++ and libg++, plain text version [Revised 01 Feb 1996]
  5. Supersedes: <g++FAQ_01_15_1996_texi@synopsys.com>
  6. Followup-To: poster
  7. Date: 1 Feb 1996 14:00:27 GMT
  8. Organization: Synopsys, Inc.
  9. Approved: news-answers-request@MIT.edu
  10. Expires: 1 Mar 1996 00:00:00 GMT
  11. Message-ID: <g++FAQ_02_01_1996_texi@synopsys.com>
  12. NNTP-Posting-Host: deerslayer.synopsys.com
  13. Originator: jbuck@deerslayer
  14.  
  15. Archive-name: g++-FAQ/plain
  16. Last-modified: 01 Feb 1996
  17. Frequency: bimonthly
  18.  
  19. [ this is the plain text version, the parent is the texinfo version ]
  20.  
  21.  
  22. FAQ for g++ and libg++, by Joe Buck (jbuck@synopsys.com)
  23. ********************************************************
  24.  
  25.    This is a list of frequently asked questions (FAQ) for g++ users;
  26. thanks to all those who sent suggestions for improvements.  Thanks to
  27. Marcus Speh for doing the index.  A hypertext version is available on
  28. the World Wide Web at `http://www.cygnus.com/misc/g++FAQ_toc.html'.
  29.  
  30.    Please send updates and corrections to the FAQ to
  31. `jbuck@synopsys.com'.  Please do *not* use me as a resource to get your
  32. questions answered; that's what gnu.g++.help is for and I don't have
  33. the time to support the net's use of g++.
  34.  
  35.    Many FAQs, including this one, are available on the archive site
  36. "rtfm.mit.edu"; see
  37. `ftp://rftm.mit.edu/pub/usenet/news.answers'.  This FAQ may be found in
  38. the subdirectory g++-FAQ.
  39.  
  40.    This FAQ is intended to supplement, not replace, Marshall Cline's
  41. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  42. Especially if g++ is the first C++ compiler you've ever used, the
  43. question "How do I do <X> with g++?" is probably really "How do I do
  44. <X> in C++?".  You can find this FAQ at
  45. `ftp://rtfm.mit.edu/pub/usenet/comp.lang.c++', or in HTML form at
  46. `http://cosmos2.phy.tufts.edu/~swinitzk/cppfaq/cppfa.htm'.
  47.  
  48. The latest poop - gcc-2.7.x
  49. ***************************
  50.  
  51.    This section is intended to describe more recent changes to g++,
  52. libg++, and such.  Some things in this section will eventually move
  53. elsewhere.
  54.  
  55.    As I write this, gcc-2.7.1 has just been released, followed in quick
  56. succession by gcc-2.7.2.  *Do not use version 2.7.1*, as there are a
  57. few serious problems.  I haven't had time to fully evaluate it yet, so
  58. some material below that refers to 2.7.0 may now be obsolete.
  59.  
  60.    I haven't had a lot of time to whip out this section yet, so
  61. suggestions for improvement are welcome.
  62.  
  63. g++ seems to want a const constructor.  What's that?
  64. ====================================================
  65.  
  66.    gcc-2.7.1 introduced a bug that causes the compiler to ask for a
  67. const constructor (there's no such thing in C++) in certain situations
  68. where a const object appears in a template class.  Most cases have been
  69. fixed in gcc-2.7.2, but unfortunately not all.  Still, if you're running
  70. gcc-2.7.1 and have this problem, upgrade to 2.7.2.
  71.  
  72. gcc-2.7.0 breaks declarations in "for" statements!
  73. ==================================================
  74.  
  75.    gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables
  76. declared in for loops.
  77.  
  78.      for (int i = 1; i <= 10; i++) {
  79.              // do something here
  80.      }
  81.      foo(i);
  82.  
  83.    In the above example, most existing C++ compilers would pass the
  84. value 11 to the function `foo'.  In gcc 2.7 and in the ANSI/ISO working
  85. paper, the scope of `i' is only the for loop body, so this is an error.
  86. So that old code can be compiled, the new gcc has a flag
  87. `-fno-for-scope' that causes the old rule to be used.
  88.  
  89.    As of 2.7.1, the compiler attempts to issue warnings about code that
  90. has different meanings under the two sets of rules, but the code is not
  91. perfect: the intent was that code that has valid, but different,
  92. meanings under the ARM rules and the working paper rules would give
  93. warnings but have the new behavior, and this doesn't seem to happen.
  94.  
  95.    The `-ffor-scope' flag under 2.7.1 and 2.7.2 gives the 2.7.0
  96. behavior.
  97.  
  98. What's new in version 2.7.0 of gcc/g++
  99. ======================================
  100.  
  101.    The long-awaited version 2.7.0 of gcc/g++ (along with a matching
  102. version of libg++) have now been released (now, so have 2.7.1 and
  103. 2.7.2).  This represents a great deal of work on the part of the g++
  104. maintainers to fix outstanding bugs and move the compiler closer to the
  105. current ANSI/ISO standards committee's working paper, including
  106. supporting many of the new features that have been added to the
  107. language.  I recommend that everyone read the NEWS file contained in
  108. the distribution (and that system administrators make the file
  109. available to their users).  I've borrowed liberally from this file here.
  110.  
  111.    If any features seem unfamiliar, you will probably want to look at
  112. the recently-released public review copy of the C++ Working Paper:
  113.    * PostScript and PDF (Adobe Acrobat): see
  114.      `ftp://research.att.com/dist/stdc++/WP'.
  115.  
  116.    * HTML and ASCII versions: see `ftp://ftp.cygnus.com/pub/g++'.
  117.  
  118.    * World Wide Web: see `http://www.cygnus.com/misc/wp/'.
  119.  
  120.    Here are the main points:
  121.  
  122.    * As described above, the scope of variables declared in the
  123.      initialization part of a for statement has been changed; such
  124.      variables are now visible only in the loop body.  Use
  125.      `-fno-for-scope' to get the old behavior.  You'll need this flag
  126.      to build groff version 1.09, Ptolemy, and many others.
  127.  
  128.    * Code that does not use #pragma interface/implementation will most
  129.      likely shrink dramatically, as g++ now only emits the vtable for a
  130.      class in the translation unit where its first non-inline,
  131.      non-abstract virtual function is defined.
  132.  
  133.    * Support for automatic template instantiation has *not* been enabled
  134.      in the official distribution, due to a disagreement over design
  135.      philosophies.  But you can get a patch from Cygnus to turn it on;
  136.      retrieve the patch from
  137.      `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz' to patch
  138.      gcc-2.7.2 (there are also patches for earlier gcc versions).
  139.  
  140.    * Support for exception handling has been improved; more targets are
  141.      now supported, and throws will use the RTTI mechanism to match
  142.      against the catch parameter type.  You must give the
  143.      `-fhandle-exceptions' to turn it on.  You must give the `-frtti'
  144.      switch to enable catching of derived exception objects with
  145.      handlers for the base exception class; if `-frtti' is not given,
  146.      only exact type matching works.
  147.  
  148.      Optimization is *not supported* with `-fhandle-exceptions'; no
  149.      need to report this as a bug.  You'll probably get an internal
  150.      compiler error if you try it.  (Q: is this better in 2.7.1?).
  151.  
  152.      For exception handling to work with 2.7.0 your CPU must be a SPARC,
  153.      RS6000/PowerPC, 386/486/Pentium, or ARM.  Release 2.7.1 added
  154.      support for the Alpha, and "m68k is rumored to work on some
  155.      platforms" and "VAX may also work" (according to Mike Stump).  It
  156.      still doesn't work on HP-PA or MIPS platforms.
  157.  
  158.    * Support for Run-Time Type Identification has been added with
  159.      `-frtti'.  This support is still in alpha; one major restriction
  160.      is that any file compiled with `-frtti' must include `<typeinfo>'
  161.      (*not* `typeinfo.h' as the NEWS file says).  Also, all code you
  162.      link with (including libg++) has to be built with `-frtti', so
  163.      it's still tricky to use.
  164.  
  165.    * Synthesis of compiler-generated constructors, destructors and
  166.      assignment operators is now deferred until the functions are used.
  167.  
  168.    * The parsing of expressions such as `a ? b : c = 1' has changed from
  169.      `(a ? b : c) = 1' to `a ? b : (c = 1)'.  This is a new C/C++
  170.      incompatibility brought to you by the ANSI/ISO standards committee.
  171.  
  172.    * The operator keywords and, and_eq, bitand, bitor, compl, not,
  173.      not_eq, or, or_eq, xor and xor_eq are now supported.  Use `-ansi'
  174.      or `-foperator-names' to enable them.
  175.  
  176.    * The `explicit' keyword is now supported.  `explicit' is used to
  177.      mark constructors and type conversion operators that should not be
  178.      used implicitly.
  179.  
  180.    * Handling of user-defined type conversion has been improved.
  181.  
  182.    * Explicit instantiation of template methods is now supported.  Also,
  183.      `inline template class foo<int>;' can be used to emit only the
  184.      vtable for a template class.
  185.  
  186.    * With -fcheck-new, g++ will check the return value of all calls to
  187.      operator new, and not attempt to modify a returned null pointer.
  188.  
  189.    * collect2 now demangles linker output, and c++filt has become part
  190.      of the gcc distribution.
  191.  
  192.    * Improvements to template instantiation: only members actually used
  193.      are instantiated.
  194.  
  195. How do I use the new repository code?
  196. =====================================
  197.  
  198.    Because there is some disagreement about the details of the template
  199. repository mechanism, you'll need to obtain a patch from Cygnus Support
  200. to enable the 2.7.2 repository code.  You can obtain the patch by
  201. anonymous FTP: `ftp://ftp.cygnus.com/pub/g++/gcc-2.7.2-repo.gz'.
  202.  
  203.    There are patches for 2.7.0 and 2.7.1 in the same directory, though
  204. if you're going to rebuild the compiler you should use the latest one.
  205.  
  206.    After you've applied the patch, the `-frepo' flag will enable the
  207. repository mechanism.  The flag works much like the existing
  208. `-fno-implicit-templates' flag, except that auxiliary files, with an
  209. `.rpo' extension, are built that specify what template expansions are
  210. needed.  At link time, the (patched) collect program detects missing
  211. templates and recompiles some of the object files so that the required
  212. templates are expanded.
  213.  
  214.    Note that the mechanism differs from that of cfront in that template
  215. definitions still must be visible at the point where they are to be
  216. expanded.  No assumption is made that `foo.C' contains template
  217. definitions corresponding to template declarations in `foo.h'.
  218.  
  219.    Jason Merrill writes: "To perform closure on a set of objects, just
  220. try to link them together.  It will fail, but as a side effect all
  221. needed instances will be generated in the objects."
  222.  
  223. Known bugs and problems with the repo patch
  224. *******************************************
  225.  
  226.    "The `-frepo' won't expand templated friend functions!"
  227.  
  228.    This is a known bug; currently you'll have to explicitly instantiate
  229. friend functions when using `-frepo' due to this bug (in 2.7.0 through
  230. 2.7.2 at least).
  231.  
  232.    With earlier versions of the repo patch, there was a bug that happens
  233. when you have given a quoted command line switch, something like
  234.  
  235.      -D'MESSAGE="hello there"'
  236.  
  237.    The repo code tries to recompile files using the same flags you
  238. originally specified, but doesn't quote arguments that need quoting,
  239. resulting in failures in some cases.  This is no longer a problem with
  240. the 2.7.2 patch.
  241.  
  242. The GNU Standard C++ Library
  243. ============================
  244.  
  245.    The GNU Standard C++ Library (also called the "GNU ANSI C++ Library"
  246. in places in the code) is not libg++, though it is included in the
  247. libg++ distribution.  Rather, it contains classes and functions
  248. required by the ANSI/ISO standard.  The copyright conditions are the
  249. same as those for for the iostreams classes; the LGPL is not used.  See
  250. *Note legalities::.
  251.  
  252.    This library, libstdc++, is in the libg++ distribution in versions
  253. 2.6.2 and later.  It requires at least gcc 2.6.3 to build the
  254. libg++-2.6.2 version; use at least gcc 2.7.0 to build the libg++ 2.7.0
  255. version.  It contains a hacked-up version of HP's implementation of the
  256. Standard Template Library (see *Note Standard Template Library::).  I've
  257. successfully used this Standard Template Library version to build a
  258. number of the demos you'll see on various web pages.
  259.  
  260.    As of version 2.7.0, the streams classes are now in libstdc++
  261. instead of libg++, and libiostream is being phased out (don't use it).
  262. The g++ program searches this library.
  263.  
  264. Obtaining Source Code
  265. *********************
  266.  
  267. What is the latest version of gcc, g++, and libg++?
  268. ===================================================
  269.  
  270.    The latest "2.x" version of gcc/g++ is 2.7.2, released November 26,
  271. 1995.  The latest version of libg++ is 2.7.1, released November 12,
  272. 1995.
  273.  
  274.    Don't use 2.5.x, with x less than 5, for C++ code; there were some
  275. serious bugs that didn't have easy workarounds.  2.5.8 is the most
  276. solid 2.5.x release.  2.6.3 is the most solid 2.6.x release.
  277.  
  278.    For some non-Unix platforms, the latest port of gcc may be an earlier
  279. version (2.5.8, say).  You'll need to use a version of libg++ that has
  280. the same first two digits as the compiler version, e.g. use libg++
  281. 2.5.x (for the latest x you can find) with gcc version 2.5.8.
  282.  
  283.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  284. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  285. programs, I recommend against using g++ 1.x except in special
  286. circumstances (and I can't think of any such circumstances).
  287.  
  288. How do I get a copy of g++ for Unix?
  289. ====================================
  290.  
  291.    First, you may already have it if you have gcc for your platform;
  292. g++ and gcc are combined now (as of gcc version 2.0).
  293.  
  294.    You can get g++ from a friend who has a copy, by anonymous FTP or
  295. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  296.  
  297.    The Free Software Foundation is a nonprofit organization that
  298. distributes software and manuals to raise funds for more GNU
  299. development.  Getting your copy from the FSF contributes directly to
  300. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  301. organization is buying, or $100 if an individual is buying.  Tapes cost
  302. around $200 depending on media type.  I recommend asking for version 2,
  303. not version 1, of g++.
  304.  
  305.    For more information about ordering from the FSF, contact
  306. gnu@prep.ai.mit.edu, phone (617) 542-5942 or anonymous ftp file
  307. `ftp://prep.ai.mit.edu/pub/gnu/GNUinfo/ORDERS' (you can also use one of
  308. the sites listed below if you can't get into "prep").
  309.  
  310.    Here is a list of anonymous FTP archive sites for GNU software.  If
  311. no directory is given, look in `/pub/gnu'.
  312.  
  313.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  314.      cair.kaist.ac.kr, ftp.nectec.or.th:/pub/mirrors/gnu
  315.      
  316.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  317.      
  318.      AFRICA: ftp.sun.ac.za
  319.      
  320.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  321.      
  322.      EUROPE: irisa.irisa.fr, ftp.univ-lyon1.fr, ftp.mcc.ac.uk,
  323.      unix.hensa.ac.uk:/pub/uunet/systems/gnu, ftp.denet.dk,
  324.      src.doc.ic.ac.uk:/gnu, ftp.eunet.ch, nic.switch.ch:/mirror/gnu,
  325.      ftp.informatik.rwth-aachen.de, ftp.informatik.tu-muenchen.de,
  326.      ftp.win.tue.nl, ftp.funet.fi, ftp.denet.dk, ftp.stacken.kth.se,
  327.      isy.liu.se, ftp.luth.se:/pub/unix/gnu, ftp.sunet.se, archive.eu.net
  328.      
  329.      SOUTH AMERICA: ftp.unicamp.br, ftp.inf.utfsm.cl
  330.      
  331.      WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  332.      
  333.      USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  334.      ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu, f.ms.uky.edu:/pub3/gnu,
  335.      jaguar.utah.edu:/gnustuff, ftp.hawaii.edu:/mirrors/gnu,
  336.      uiarchive.cso.uiuc.edu:/pub/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  337.      col.hp.com:/mirrors/gnu, gatekeeper.dec.com:/pub/GNU,
  338.      ftp.uu.net:/systems/gnu
  339.  
  340.    The "official site" is prep.ai.mit.edu, but your transfer will
  341. probably go faster if you use one of the above machines.
  342.  
  343.    Most GNU utilities are compressed with "gzip", the GNU compression
  344. utility.  All GNU archive sites should have a copy of this program,
  345. which you will need to uncompress the distributions.
  346.  
  347.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  348. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  349. Ohio State University.  You pay for the long-distance call to OSU; the
  350. price isn't too bad on weekends at 9600 bps.  Send mail to
  351. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  352.  
  353.    OSU lines are often busy.  If you're in the USA, and are willing to
  354. spend more money, you can get sources via UUCP from UUNET using their
  355. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  356. You will be billed $0.50/minute by your phone company.
  357.  
  358.    Don't forget to retrieve libg++ as well!
  359.  
  360. Getting gcc/g++ for the HP Precision Architecture
  361. =================================================
  362.  
  363.    If you use the HP Precision Architecture (HP-9000/7xx and
  364. HP-9000/8xx) and you want to use debugging, you'll need to use the GNU
  365. assembler, GAS (version 2.3 or later).  If you build from source, you
  366. must tell the configure program that you are using GAS or you won't get
  367. debugging support.  A non-standard debug format is used, since until
  368. recently HP considered their debug format a trade secret.  Thanks to
  369. the work of lots of good folks both inside and outside HP, the company
  370. has seen the error of its ways and has now released the required
  371. information.  The team at the University of Utah that did the gcc port
  372. now has code that understands the native HP format.
  373.  
  374.    Some enhancements for the HP that haven't been integrated back into
  375. the official GCC are available from the University of Utah, site
  376. jaguar.cs.utah.edu.  You can retrieve sources and prebuilt binaries for
  377. GCC, GDB, binutils,and libg++; see the directory `/dist'.
  378.  
  379.    The libg++ version is actually the same as the FSF 2.6.  The Utah
  380. version of GDB can now understand both the GCC and HP C compiler debug
  381. formats, so it is no longer necessary to have two different GDB
  382. versions.
  383.  
  384.    I recommend that HP users use the Utah versions of the tools (see
  385. above), though at this point the standard FSF versions will work well.
  386.  
  387.    HP GNU users can also find useful stuff on the site geod.emr.ca in
  388. the `/pub/UNIX/GNU-HP' directory.
  389.  
  390.    Jeff Law is leaving the University of Utah, so the Utah prebuilt
  391. binaries may be discontinued.
  392.  
  393. Getting gcc/g++ binaries for Solaris 2.x
  394. ========================================
  395.  
  396.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  397.  
  398.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  399. Solaris.  As a rule, these binaries are not updated as often as the
  400. sources are, so if you want the very latest version of gcc/g++, you may
  401. need to grab and install binaries for an older version and use it to
  402. bootstrap the latest version from source.
  403.  
  404.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  405. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  406. Solaris on Intel 386/486 machines (the Solaris/Intel binaries seem to
  407. be gone from prep but still exist on some mirrors).
  408.  
  409.    There are also binaries for "gzip", the GNU compression utility,
  410. which you'll need for uncompressing the binary distribution.  On any GNU
  411. archive site, look in subdirectories `i486-sun-solaris2' or
  412. `sparc-sun-solaris2'.
  413.  
  414.    The ftp directory `ftp://ftp.quintus.com/pub/GNU' contains various
  415. GNU and freeware programs for Solaris2.X running on the sparc. These are
  416. packaged to enable installation using the Solaris "pkgadd" utility.
  417. These include GNU emacs 19.27, gcc (and g++) 2.6.0, Perl 4.036, and
  418. others.
  419.  
  420. How do I get a copy of g++ for (some other platform)?
  421. =====================================================
  422.  
  423.    As of gcc-2.7.x, there is Windows NT support in gcc.  Some special
  424. utilities are required.  See the INSTALL file from the distribution.
  425. If you're interested in GNU tools on Windows NT, see
  426. `http://www.cygnus.com/misc/gnu-win32/' on the WWW, or the anonymous
  427. FTP directory `ftp://ftp.cygnus.com/pub/gnu-win32/'.
  428.  
  429.    The standard gcc/g++ distribution includes VMS support.  Since the
  430. FSF people don't use VMS, it's likely to be somewhat less solid than
  431. the Unix version.  Precompiled copies of g++ and libg++ in
  432. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  433. See also `ftp://ftp.stacken.kth.se/pub/GNU-VMS/contrib', the site (in
  434. Sweden) which has gcc-2.5.8 and libg++-2.5.3.
  435.  
  436.    There are two different versions of gcc/g++ for MS-DOS: EMX and
  437. DJGPP.  EMX also works for OS/2 and is described later.  DJGPP is DJ
  438. Delorie's port.  It can be found on many FTP archive sites; its "home"
  439. is `ftp://oak.oakland.edu/pub/msdos/djgpp/'.
  440.  
  441.    The latest version of DJGPP is 1.12.maint4, a port of gcc-2.6.3 plus
  442. support software.  This version runs under Windows 3.x.  There's also a
  443. beta-2.00 version.
  444.  
  445.    FSF sells floppies with DJGPP on them; see above for ordering
  446. software from the FSF.
  447.  
  448.    DJGPP has its own newsgroup: `news:comp.os.msdos.djgpp'.
  449.  
  450.    For information on Amiga ports of gcc/g++, retrieve the file
  451. `ftp://prep.ai.mit.edu/pub/gnu/MicrosPorts/Amiga' or write to Markus M.
  452. Wild <wild@nessie.cs.id.ethz.ch>, who I hope won't be too upset that I
  453. mentioned his name here.
  454.  
  455.    A port of gcc to the Atari ST can be found at
  456. `ftp://atari.archive.umich.edu/atari/Gnustuff/Tos' along with many
  457. other GNU programs.  This version is usually the same as the latest FSF
  458. release.  See the "Software FAQ" for the Usenet group
  459. "comp.sys.atari.st" for more information.
  460.  
  461.    There are two different ports of gcc to OS/2, the so-called EMX port
  462. (which also runs on MS-DOS), and a port called "gcc/2".  The latter
  463. port is no longer supported, since the EMX port includes all of its
  464. functionality.  The EMX port's C library attempts to provide a
  465. Unix-like environment.  For more information ask around on
  466. "comp.os.os2.programmer.misc".
  467.  
  468.    The EMX port is available by FTP from
  469.  
  470.      ftp://ftp.uni-stuttgart.de/pub/systems/os2/emx-0.9a
  471.      ftp://src.doc.ic.ac.uk/pub/packages/os2/unix/emx09a
  472.      ftp://ftp.informatik.tu-muenchen.de/pub/comp/os/os2/devtools/emx+gcc
  473.  
  474.    Eberhard Mattes did the EMX port.  His address is
  475. mattes@azu.informatik.uni-stuttgart.de.
  476.  
  477.    I'm looking for more information on gcc/g++ support on the Apple
  478. Macintosh.  Until recently, this FAQ did not provide such information,
  479. but FSF is no longer boycotting Apple as the League for Programming
  480. Freedom boycott has been dropped.
  481.  
  482.    Versions 1.37.1 and 2.3.3 of gcc were ported by Stan Shebs and are
  483. available at
  484. `ftp://ftp.cygnus.com/pub/mac'
  485.  
  486.    They are both interfaced to MPW.  Stan is working on a version using
  487. the current (post-2.7) sources, contact him directly (shebs@cygnus.com)
  488. for more information.
  489.  
  490. But I can only find g++-1.42!
  491. =============================
  492.  
  493.    "I keep hearing people talking about g++ 2.7.2 (or some other number
  494. starting with 2), but the latest version I can find is g++ 1.42.  Where
  495. is it?"
  496.  
  497.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  498. a single distribution called gcc.  If you get gcc you already have g++.
  499. The standard installation procedure for any gcc version 2 compiler will
  500. install the C++ compiler as well.
  501.  
  502.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  503. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  504.  
  505. Installation Issues and Problems
  506. ********************************
  507.  
  508. I can't build g++ 1.x.y with gcc-2.x.y!
  509. =======================================
  510.  
  511.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  512. I'm having major problems.  What's going on?"
  513.  
  514.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  515. installation instructions for g++ version 1 leave a lot to be desired,
  516. unfortunately, and I would recommend that, unless you have a special
  517. reason for needing the 1.x compiler, that C++ users use the latest
  518. g++-2.x version, as it is the version that is being actively maintained.
  519.  
  520.    There is no template support in g++-1.x, and it is generally much
  521. further away from the ANSI draft standard than g++-2.x is.
  522.  
  523. OK, I've obtained gcc; what else do I need?
  524. ===========================================
  525.  
  526.    First off, you'll want libg++ as you can do almost nothing without it
  527. (unless you replace it with some other class library).
  528.  
  529.    Second, depending on your platform, you may need "GAS", the GNU
  530. assembler, or the GNU linker (see next question).
  531.  
  532.    Finally, while it is not required, you'll almost certainly want the
  533. GNU debugger, gdb.  The latest version is 4.15.1, released November 4,
  534. 1995.  Other debuggers (like dbx, for example) will normally not be
  535. able to understand at least some of the debug information produced by
  536. g++.
  537.  
  538. Should I use the GNU linker, or should I use "collect"?
  539. =======================================================
  540.  
  541.    First off, for novices: special measures must be taken with C++ to
  542. arrange for the calling of constructors for global or static objects
  543. before the execution of your program, and for the calling of
  544. destructors at the end.  (Exception: System VR3 and System VR4 linkers,
  545. Linux/ELF, and some other systems support user-defined segments; g++ on
  546. these systems requires neither the GNU linker nor collect.  So if you
  547. have such a system, the answer is that you don't need either one).
  548.  
  549.    If you have experience with AT&T's "cfront", this function is
  550. performed there by programs named "patch" or "munch".  With GNU C++, it
  551. is performed either by the GNU linker or by a program known as
  552. "collect".  The collect program is part of the gcc-2.x distribution;
  553. you can obtain the GNU linker separately as part of the "binutils"
  554. package.  The latest version of binutils is 2.5.2, released November 2,
  555. 1994.
  556.  
  557.    (To be technical, it's "collect2"; there were originally several
  558. alternative versions of collect, and this is the one that survived).
  559.  
  560.    There are advantages and disadvantages to either choice.
  561.  
  562.    Advantages of the GNU linker:
  563.  
  564.    It's faster than using collect - collect basically runs the standard
  565. Unix linker on your program twice, inserting some extra code after the
  566. first pass to call the constructors.  This is a sizable time penalty
  567. for large programs.  The GNU linker does not require this extra pass.
  568.  
  569.    GNU ld reports undefined symbols using their true names, not the
  570. mangled names (but as of 2.7.0 so does collect).
  571.  
  572.    If there are undefined symbols, GNU ld reports which object file(s)
  573. refer to the undefined symbol(s).
  574.  
  575.    As of binutils version 2.2, on systems that use the so-called "a.out"
  576. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  577. the debug symbol table considerably.
  578.  
  579.    Advantages of collect:
  580.  
  581.    If your native linker supports shared libraries, you can use shared
  582. libraries with collect.  This used to be a strong reason *not* to use
  583. the GNU linker, but recent versions of GNU ld support linking with
  584. shared libraries on many platforms, and creating shared libraries on a
  585. few (such as Intel x86 systems that use ELF object format).
  586.  
  587.    Note: using existing shared libraries (X and libc, for example) works
  588. very nicely.  Generating shared libraries from g++-compiled code is
  589. another matter, generally requiring OS-dependent tricks if it is
  590. possible at all.  But progress has been made recently.
  591.  
  592.    As of 2.7.0, building C++ shared libraries should work fine on
  593. supported platforms (HPUX 9+, IRIX 5+, DEC UNIX (formerly OSF/1), SunOS
  594. 4, Linux/ELF and all targets using SVR4-style ELF shared libraries).
  595.  
  596.    However, as of libg++ 2.6.2, the libg++ distribution contains some
  597. patches to build libg++ as a shared library on some OSes (those listed
  598. above).  Check the file `README.SHLIB' from that distribution.
  599.  
  600.    The GNU linker has not been ported to as many platforms as g++ has,
  601. so you may be forced to use collect.
  602.  
  603.    If you use collect, you don't need to get something extra and figure
  604. out how to install it; the standard gcc installation procedure will do
  605. it for you.
  606.  
  607.    In conclusion, I don't see a clear win for either alternative at this
  608. point.  Take your pick.
  609.  
  610. Should I use the GNU assembler, or my vendor's assembler?
  611. =========================================================
  612.  
  613.    This depends on your platform and your decision about the GNU
  614. linker.  For most platforms, you'll need to use GAS if you use the GNU
  615. linker.  For some platforms, you have no choice; check the gcc
  616. installation notes to see whether you must use GAS.  But you can
  617. usually use the vendor's assembler if you don't use the GNU linker.
  618.  
  619.    The GNU assembler assembles faster than many native assemblers;
  620. however, on many platforms it cannot support the local debugging format.
  621.  
  622.    If you want to build shared libraries from gcc/g++ output and you
  623. are on a Sun, you must *not* use GNU as, as it cannot do
  624. position-independent code correctly yet.  *Note*: I've been told that
  625. this problem has been fixed in the most recent binutils release, but I
  626. haven't checked this yet.
  627.  
  628.    On HPUX or IRIX, you must use GAS (and configure gcc with the
  629. `--with-gnu-as' option) to debug your programs.  GAS is strongly
  630. recommended particularly on the HP platform because of limitations in
  631. the HP assembler.
  632.  
  633.    The GAS distribution has recently been merged with the binutils
  634. distribution, so the GNU assembler and linker are now together in this
  635. package (as of binutils version 2.5.1).
  636.  
  637. Should I use the GNU C library?
  638. ===============================
  639.  
  640.    At this point in time, no.  The GNU C library is still very young,
  641. and libg++ still conflicts with it in some places.  Use your native C
  642. library unless you know a lot about the gory details of libg++ and
  643. gnu-libc.  This will probably change in the future.
  644.  
  645. Global constructors aren't being called
  646. =======================================
  647.  
  648.    "I've installed gcc and it almost works, but constructors and
  649. destructors for global objects and objects at file scope aren't being
  650. called.  What did I do wrong?"
  651.  
  652.    It appears that you are running on a platform that requires you to
  653. install either "collect2" or the GNU linker, and you have done neither.
  654. For more information, see the section discussing the GNU linker (*Note
  655. use GNU linker?::).
  656.  
  657.    On Solaris 2.x, you shouldn't need a collect program and GNU ld
  658. doesn't run.  If your global constructors aren't being called, you may
  659. need to install a patch, available from Sun, to fix your linker.  The
  660. number of the "jumbo patch" that applies is 101409-03.  Thanks to
  661. Russell Street (r.street@auckland.ac.nz) for this info.
  662.  
  663.    It appears that on IRIX, the collect2 program is not being installed
  664. by default during the installation process, though it is required; you
  665. can install it manually by executing
  666.  
  667.      make install-collect2
  668.  
  669.    from the gcc source directory after installing the compiler.  (I'm
  670. not certain for which versions of gcc this problem occurs, and whether
  671. it is still present).
  672.  
  673. Strange assembler errors when linking C++ programs
  674. ==================================================
  675.  
  676.    "I've installed gcc and it seemed to go OK, but when I attempt to
  677. link any C++ program, I'm getting strange errors from the assembler!
  678. How can that be?"
  679.  
  680.    The messages in question might look something like
  681.  
  682.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  683.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  684.  
  685.    (on a Sun, different on other platforms).  The important thing is
  686. that the errors come out at the link step, *not* when a C++ file is
  687. being compiled.
  688.  
  689.    Here's what's going on: the collect2 program uses the Unix "nm"
  690. program to obtain a list of symbols for the global constructors and
  691. destructors, and it builds a little assembly language module that will
  692. permit them all to be called.  If you're seeing this symptom, you have
  693. an old version of GNU nm somewhere on your path.  This old version
  694. prints out symbol names in a format that the collect2 program does not
  695. expect, so bad assembly code is generated.
  696.  
  697.    The solution is either to remove the old version of GNU nm from your
  698. path (and that of everyone else who uses g++), or to install a newer
  699. version (it is part of the GNU "binutils" package).  Recent versions of
  700. GNU nm do not have this problem.
  701.  
  702. Other problems building libg++
  703. ==============================
  704.  
  705.    "I am having trouble building libg++.  Help!"
  706.  
  707.    On some platforms (for example, Ultrix), you may see errors
  708. complaining about being unable to open dummy.o.  On other platforms
  709. (for example, SunOS), you may see problems having to do with the type
  710. of size_t.  The fix for these problems is to make libg++ by saying
  711. "make CC=gcc".  According to Per Bothner, it should no longer be
  712. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  713.  
  714.    "I built and installed libg++, but g++ can't find it.  Help!"
  715.  
  716.    The string given to `configure' that identifies your system must be
  717. the same when you install libg++ as it was when you installed gcc.
  718. Also, if you used the `--prefix' option to install gcc somewhere other
  719. than `/usr/local', you must use the same value for `--prefix' when
  720. installing libg++, or else g++ will not be able to find libg++.
  721.  
  722.    The toplevel Makefile in the libg++ 2.6.2 distribution is broken,
  723. which along with a bug in g++ 2.6.3 causes problems linking programs
  724. that use the libstdc++ complex classes.  A patch for this is available
  725. from `ftp://ftp.cygnus.com//pub/g++/libg++-2.6.2-fix.gz'.
  726.  
  727. But I'm *still* having problems with `size_t'!
  728. ==============================================
  729.  
  730.    "I did all that, and I'm *still* having problems with disagreeing
  731. definitions of size_t, SIZE_TYPE, and the type of functions like
  732. `strlen'."
  733.  
  734.    The problem may be that you have an old version of `_G_config.h'
  735. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  736. platform-specific, is inserted into a different directory; most include
  737. files are in `$prefix/lib/g++-include', but this file now lives in
  738. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  739. there is an old copy of `_G_config.h' left around, remove it, otherwise
  740. g++ will find the old one first.
  741.  
  742. Do I need to rebuild libg++ to go with my new g++?
  743. ==================================================
  744.  
  745.    "After I upgraded g++ to the latest version, I'm seeing undefined
  746. symbols."
  747.  
  748.    or
  749.  
  750.    "If I upgrade to a new version of g++, do I need to reinstall
  751. libg++?"
  752.  
  753.    As a rule, the first two digits of your g++ and libg++ should be the
  754. same.  Normally when you do an upgrade in the "minor version number"
  755. (2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but there
  756. have been a couple of exceptions in the past.
  757.  
  758. Trouble installing g++ and libg++ on Linux
  759. ******************************************
  760.  
  761.    "I've downloaded the latest g++ and libg++ and I'm trying to install
  762. them on Linux, and I'm having lots of problems."
  763.  
  764.    FSF releases of libg++ won't install on Linux unchanged, since Linux
  765. uses are part of the libio library from libg++ for its standard C
  766. library, only this is changed in a way that it clashes with libg++.
  767. This means that you'll need a patched version of libg++ for it to work.
  768.  
  769.    If you want to upgrade to a new gcc/libg++ combination, the easiest
  770. thing to do is to grab the prebuilt versions of gcc and libg++ for Linux
  771. from `ftp://tsx-11.mit.edu/pub/linux/packages/GCC'.  Follow the
  772. directions carefully.  If you want to build from source, you'll need a
  773. patch for libg++; the Linux developers have named the patched libg++
  774. version libg++-2.7.1.3 and there is a patch file in the above-named
  775. directory.
  776.  
  777.    See `ftp://www.mrc-apu.cam.ac.uk/pub/linux/GCC-FAQ.html', the Linux
  778. GCC FAQ (though it may be a bit out of date; the Linux community moves
  779. quickly).
  780.  
  781. Problems with g++ on Linux Slackware 3.0
  782. ****************************************
  783.  
  784.    "When I try to compile the traditional Hello, world program on Linux,
  785. the compiler can't find `iostream.h'.  What's the deal?"
  786.  
  787.    You probably have the Slackware 3.0 release.  There's an error in the
  788. setup.  It's easy to fix, though; log in as root, and make a symbolic
  789. link:
  790.  
  791.      ln -s /usr/lib/g++-include /usr/include/g++
  792.  
  793. User Problems
  794. *************
  795.  
  796. How to silence "unused parameter" warnings
  797. ==========================================
  798.  
  799.    "When I use `-Wall' (or `-Wunused'), g++ warns about unused
  800. parameters.  But the parameters have to be there, for use in derived
  801. class functions.  How do I get g++ to stop complaining?"
  802.  
  803.    The answer is to simply omit the names of the unused parameters when
  804. defining the function.  This makes clear, both to g++ and to readers of
  805. your code, that the parameter is unused.  For example:
  806.  
  807.      int Foo::bar(int arg) { return 0; }
  808.  
  809.    will give a warning for the unused parameter `arg'.  To suppress the
  810. warning write
  811.  
  812.      int Foo::bar(int) { return 0; }
  813.  
  814. g++ objects to a declaration in a case statement
  815. ================================================
  816.  
  817.    "The compiler objects to my declaring a variable in one of the
  818. branches of a case statement.  Earlier versions used to accept this
  819. code.  Why?"
  820.  
  821.    The draft standard does not allow a goto or a jump to a case label to
  822. skip over an initialization of a variable or a class object.  For
  823. example:
  824.  
  825.      switch ( i ) {
  826.        case 1:
  827.          Object obj(0);
  828.              ...
  829.          break;
  830.        case 2:
  831.          ...
  832.          break;
  833.      }
  834.  
  835.    The reason is that `obj' is also in scope in the rest of the switch
  836. statement.
  837.  
  838.    As of version 2.7.0, the compiler will object that the jump to the
  839. second case level crosses the initialization of `obj'.  Older compiler
  840. versions would object only if class Object has a destructor.  In either
  841. case, the solution is to add a set of curly braces around the case
  842. branch:
  843.  
  844.        case 1:
  845.          {
  846.             Object obj(0);
  847.              ...
  848.             break;
  849.          }
  850.  
  851. gcc 2.5.x broke my code!  Changes in function overloading
  852. =========================================================
  853.  
  854.    "I have a program that worked just fine with older g++ versions, but
  855. as of version 2.5.x it doesn't work anymore.  Help!"
  856.  
  857.    While it's always possible that a new bug has been introduced into
  858. the compiler, it's also possible that you have been relying on bugs in
  859. older versions of g++.  For example, version 2.5.0 was the first
  860. version of g++ to correctly implement the "hiding rule."  That is, if
  861. you have an overloaded function in a base class, and in a derived class
  862. you redefine one of the names, the other names are effectively "hidden".
  863. *All* the names from the baseclass need to be redefined in the derived
  864. class.  See section 13.1 of the ARM: "A function member of a derived
  865. class is *not* in the same scope as a function member of the same name
  866. in a base class".
  867.  
  868.    Here's an example that is handled incorrectly by g++ versions before
  869. 2.5.0 and correctly by newer versions:
  870.  
  871.      class Base {
  872.      public:
  873.          void foo(int);
  874.      };
  875.      
  876.      class Derived : public Base {
  877.      public:
  878.          void foo(double);  // *note that Base::foo(int) is hidden*
  879.      };
  880.      
  881.      main() {
  882.          Derived d;
  883.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  884.      }
  885.  
  886. Where can I find a demangler?
  887. =============================
  888.  
  889.    A g++-compatible demangler named `c++filt' can be found in the
  890. `binutils' distribution.  This distribution (which also contains the
  891. GNU linker) can be found at any GNU archive site.
  892.  
  893.    As of version 2.7.0, `c++filt' is included with gcc and is installed
  894. automatically.  Even better, it is used by the `collect' linker, so you
  895. don't see mangled symbols anymore.
  896.  
  897. Where can I find a version of etags for C++?
  898. ============================================
  899.  
  900.    The libg++ distribution contains a version of etags that works for
  901. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  902. install libg++, but you can cd to that directory and type
  903.  
  904.      make etags
  905.  
  906.    after you've installed libg++.
  907.  
  908. Linker reports undefined symbols for static data members
  909. ========================================================
  910.  
  911.    "g++ reports undefined symbols for all my static data members when I
  912. link, even though the program works correctly for compiler XYZ.  What's
  913. going on?"
  914.  
  915.    The problem is almost certainly that you don't give definitions for
  916. your static data members.  If you have
  917.  
  918.      class Foo {
  919.          ...
  920.          void method();
  921.          static int bar;
  922.      };
  923.  
  924.    you have only declared that there is an int named Foo::bar and a
  925. member function named Foo::method that is defined somewhere.  You still
  926. need to define *both* method() and bar in some source file.  According
  927. to the draft ANSI standard, you must supply an initializer, such as
  928.  
  929.      int Foo::bar = 0;
  930.  
  931. in one (and only one) source file.
  932.  
  933. What does "Internal compiler error" mean?
  934. =========================================
  935.  
  936.    It means that the compiler has detected a bug in itself.
  937. Unfortunately, g++ still has many bugs, though it is a lot better than
  938. it used to be.  If you see this message, please send in a complete bug
  939. report (see next section).
  940.  
  941. I think I have found a bug in g++.
  942. ==================================
  943.  
  944.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  945. and who should I tell?"
  946.  
  947.    First, see the excellent section on bugs and bug reports in the gcc
  948. manual (which is included in the gcc distribution).  As a short summary
  949. of that section: if the compiler gets a fatal signal, for any input,
  950. it's a bug (newer versions of g++ will ask you to send in a bug report
  951. when they detect an error in themselves).  Same thing for producing
  952. invalid assembly code.
  953.  
  954.    When you report a bug, make sure to describe your platform (the type
  955. of computer, and the version of the operating system it is running) and
  956. the version of the compiler that you are running.  See the output of the
  957. command `g++ -v' if you aren't sure.  Also provide enough code so that
  958. the g++ maintainers can duplicate your bug.  Remember that the
  959. maintainers won't have your header files; one possibility is to send
  960. the output of the preprocessor (use `g++ -E' to get this).  This is
  961. what a "complete bug report" means.
  962.  
  963.    I will add some extra notes that are C++-specific, since the notes
  964. from the gcc documentation are generally C-specific.
  965.  
  966.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  967. also post to gnu.g++.bug, but it's better to use mail, particularly if
  968. you have any doubt as to whether your news software generates correct
  969. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  970.  
  971.    If your bug involves libg++ rather than the compiler, mail to
  972. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  973. guessed wrong, the maintainers will forward it to the other list.
  974.  
  975.    Second, if your program does one thing, and you think it should do
  976. something else, it is best to consult a good reference if in doubt.
  977. The standard reference is the draft working paper from the ANSI/ISO C++
  978. standardization committee, which you can get on the net.  For
  979. PostScript and PDF (Adobe Acrobat) versions, see the archive at
  980. `ftp://research.att.com/dist/stdc++/WP'.  For HTML and ASCII versions,
  981. see `ftp://ftp.cygnus.com/pub/g++'.  On the World Wide Web, see
  982. `http://www.cygnus.com/~mrs/misc/wp/'.
  983.  
  984.    An older standard reference is "The Annotated C++ Reference Manual",
  985. by Ellis and Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is
  986. what they're talking about on the net when they refer to "the ARM".
  987. But you should know that changes have been made to the language since
  988. then.
  989.  
  990.    The ANSI/ISO C++ standards committee have adopted some changes to the
  991. C++ language since the publication of the original ARM, and newer
  992. versions of g++ (2.5.x and later) support some of these changes, notably
  993. the mutable keyword (added in 2.5.0), the bool type (added in 2.6.0),
  994. and changes in the scope of variables defined in for statements (added
  995. in 2.7.0).  You can obtain an addendum to the ARM explaining many of
  996. these changes by FTP from
  997. `ftp://ftp.std.com/AW/stroustrup2e/new_iso.ps'.
  998.  
  999.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  1000. is NOT the standard for the language.
  1001.  
  1002. Porting programs from other compilers to g++
  1003. ============================================
  1004.  
  1005.    "I have a program that runs on <some other C++ compiler>, and I want
  1006. to get it running under g++.  Is there anything I should watch out for?"
  1007.  
  1008.    Note that g++ supports many of the newer keywords that have recently
  1009. been added to the language.  Your other C++ compiler may not support
  1010. them, so you may need to rename variables and members that conflict
  1011. with these keywords.
  1012.  
  1013.    There are two other reasons why a program that worked under one
  1014. compiler might fail under another: your program may depend on the order
  1015. of evaluation of side effects in an expression, or it may depend on the
  1016. lifetime of a temporary (you may be assuming that a temporary object
  1017. "lives" longer than the standard guarantees).  As an example of the
  1018. first:
  1019.  
  1020.      void func(int,int);
  1021.      
  1022.      int i = 3;
  1023.      func(i++,i++);
  1024.  
  1025.    Novice programmers think that the increments will be evaluated in
  1026. strict left-to-right order.  Neither C nor C++ guarantees this; the
  1027. second increment might happen first, for example.  func might get 3,4,
  1028. or it might get 4,3.
  1029.  
  1030.    The second problem often happens with classes like the libg++ String
  1031. class.  Let's say I have
  1032.  
  1033.      String func1();
  1034.      void func2(const char*);
  1035.  
  1036.    and I say
  1037.  
  1038.      func2(func1());
  1039.  
  1040.    because I know that class String has an "operator const char*".  So
  1041. what really happens is
  1042.  
  1043.      func2(func1().convert());
  1044.  
  1045.    where I'm pretending I have a convert() method that is the same as
  1046. the cast.  This is unsafe in g++ versions before 2.6.0, because the
  1047. temporary String object may be deleted after its last use (the call to
  1048. the conversion function), leaving the pointer pointing to garbage, so by
  1049. the time func2 is called, it gets an invalid argument.
  1050.  
  1051.    Both the cfront and the old g++ behaviors are legal according to the
  1052. ARM, but the powers that be have decided that compiler writers were
  1053. given too much freedom here.
  1054.  
  1055.    The ANSI C++ committee has now come to a resolution of the lifetime
  1056. of temporaries problem: they specify that temporaries should be deleted
  1057. at end-of-statement (and at a couple of other points).  This means that
  1058. g++ versions before 2.6.0 now delete temporaries too early, and cfront
  1059. deletes temporaries too late.  As of version 2.6.0, g++ does things
  1060. according to the new standard.
  1061.  
  1062.    For now, the safe way to write such code is to give the temporary a
  1063. name, which forces it to live until the end of the scope of the name.
  1064. For example:
  1065.  
  1066.      String& tmp = func1();
  1067.      func2(tmp);
  1068.  
  1069.    Finally, like all compilers (but especially C++ compilers, it seems),
  1070. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  1071. report (after checking the above issues).
  1072.  
  1073. Why does g++ mangle names differently from other C++ compilers?
  1074. ===============================================================
  1075.  
  1076.    See the answer to the next question.
  1077.  
  1078. Why can't g++ code link with code from other C++ compilers?
  1079. ===========================================================
  1080.  
  1081.    "Why can't I link g++-compiled programs against libraries compiled by
  1082. some other C++ compiler?"
  1083.  
  1084.    Some people think that, if only the FSF and Cygnus Support folks
  1085. would stop being stubborn and mangle names the same way that, say,
  1086. cfront does, then any g++-compiled program would link successfully
  1087. against any cfront-compiled library and vice versa.  Name mangling is
  1088. the least of the problems.  Compilers differ as to how objects are laid
  1089. out, how multiple inheritance is implemented, how virtual function
  1090. calls are handled, and so on, so if the name mangling were made the
  1091. same, your programs would link against libraries provided from other
  1092. compilers but then crash when run.  For this reason, the ARM
  1093. *encourages* compiler writers to make their name mangling different
  1094. from that of other compilers for the same platform.  Incompatible
  1095. libraries are then detected at link time, rather than at run time.
  1096.  
  1097. What documentation exists for g++ 2.x?
  1098. ======================================
  1099.  
  1100.    Relatively little.  While the gcc manual that comes with the
  1101. distribution has some coverage of the C++ part of the compiler, it
  1102. focuses mainly on the C compiler (though the information on the "back
  1103. end" pertains to C++ as well).  Still, there is useful information on
  1104. the command line options and the #pragma interface and #pragma
  1105. implementation directives in the manual, and there is a useful section
  1106. on template instantiation in the 2.6 version.  There is a Unix-style
  1107. manual entry, "g++.1", in the gcc-2.x distribution; the information
  1108. here is a subset of what is in the manual.
  1109.  
  1110.    You can buy a nicely printed and bound copy of this manual from the
  1111. FSF; see above for ordering information.
  1112.  
  1113.    For versions 2.6.2 and later, the gcc/g++ distribution contains the
  1114. gcc manual in PostScript.  Also, Postscript versions of GNU
  1115. documentation in U.S. letter format are available by anonymous FTP from
  1116. `ftp://primus.com/pub/gnu-ps'.  The same, in A4 format, are on
  1117. `ftp://liasun3.epfl.ch/pub/gnu/ps-doc'.
  1118.  
  1119.    A draft of a document describing the g++ internals appears in the gcc
  1120. distribution (called g++int.texi); it is incomplete but gives lots of
  1121. information.
  1122.  
  1123. Problems with the template implementation
  1124. =========================================
  1125.  
  1126.    g++ does not implement a separate pass to instantiate template
  1127. functions and classes at this point; for this reason, it will not work,
  1128. for the most part, to declare your template functions in one file and
  1129. define them in another.  The compiler will need to see the entire
  1130. definition of the function, and will generate a static copy of the
  1131. function in each file in which it is used.
  1132.  
  1133.    (The experimental template repository code (see *Note repository::)
  1134. that can be added to 2.7.0 or later does implement a separate pass, but
  1135. there is still no searching of files that the compiler never saw).
  1136.  
  1137.    For version 2.6.0, however, a new switch `-fno-implicit-templates'
  1138. was added; with this switch, templates are expanded only under user
  1139. control.  I recommend that all g++ users that use templates read the
  1140. section "Template Instantiation" in the gcc manual (version 2.6.x and
  1141. newer).  g++ now supports explicit template expansion using the syntax
  1142. from the latest C++ working paper:
  1143.  
  1144.      template class A<int>;
  1145.      template ostream& operator << (ostream&, const A<int>&);
  1146.  
  1147.    As of version 2.6.3, there are still a few limitations in the
  1148. template implementation besides the above (thanks to Jason Merrill for
  1149. this info):
  1150.  
  1151.   1. Static data member templates are not supported.  You can work
  1152.      around this by explicitly declaring the static variable for each
  1153.      template specialization:
  1154.  
  1155.           template <class T> struct A {
  1156.             static T t;
  1157.           };
  1158.           
  1159.           template <class T> T A<T>::t = 0; // gets bogus error
  1160.           int A<int>::t = 0;                // OK (workaround)
  1161.  
  1162.      (still a limitation in 2.7.0)
  1163.  
  1164.   2. Template member names are not available when defining member
  1165.      function templates.
  1166.  
  1167.           template <class T> struct A {
  1168.             typedef T foo;
  1169.             void f (foo);
  1170.             void g (foo arg) { ... }; // this works
  1171.           };
  1172.           
  1173.           template <class T> void A<T>::f (foo) { } // gets bogus error
  1174.  
  1175.   3. Templates are instantiated using the parser.  This results in two
  1176.      problems:
  1177.  
  1178.      a) Class templates are instantiated in some situations where such
  1179.      instantiation should not occur.
  1180.  
  1181.           template <class T> class A { };
  1182.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  1183.  
  1184.      b) Function templates cannot be inlined at the site of their
  1185.      instantiation.
  1186.  
  1187.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  1188.           
  1189.           void f () {
  1190.             int i = min (1, 0);           // not inlined
  1191.           }
  1192.           
  1193.           void g () {
  1194.             int j = min (1, 0);           // inlined
  1195.           }
  1196.  
  1197.      A workaround that works in version 2.6.1 and later is to specify
  1198.  
  1199.           extern template int min (int, int);
  1200.  
  1201.      before `f()'; this will force it to be instantiated (though not
  1202.      emitted).
  1203.  
  1204.   4. Member function templates are always instantiated when their
  1205.      containing class is.  This is wrong.
  1206.  
  1207. I get undefined symbols when using templates
  1208. ============================================
  1209.  
  1210.    (Thanks to Jason Merrill for this section).
  1211.  
  1212.    g++ does not automatically instantiate templates defined in other
  1213. files.  Because of this, code written for cfront will often produce
  1214. undefined symbol errors when compiled with g++.  You need to tell g++
  1215. which template instances you want, by explicitly instantiating them in
  1216. the file where they are defined.  For instance, given the files
  1217.  
  1218.    `templates.h':
  1219.      template <class T>
  1220.      class A {
  1221.      public:
  1222.        void f ();
  1223.        T t;
  1224.      };
  1225.      
  1226.      template <class T> void g (T a);
  1227.  
  1228.    `templates.cc':
  1229.      #include "templates.h"
  1230.      
  1231.      template <class T>
  1232.      void A<T>::f () { }
  1233.      
  1234.      template <class T>
  1235.      void g (T a) { }
  1236.  
  1237.    main.cc:
  1238.      #include "templates.h"
  1239.      
  1240.      main ()
  1241.      {
  1242.        A<int> a;
  1243.        a.f ();
  1244.        g (a);
  1245.      }
  1246.  
  1247.    compiling everything with `g++ main.cc templates.cc' will result in
  1248. undefined symbol errors for `A<int>::f ()' and `g (A<int>)'.  To fix
  1249. these errors, add the lines
  1250.  
  1251.      template class A<int>;
  1252.      template void g (A<int>);
  1253.  
  1254.    to the bottom of `templates.cc' and recompile.
  1255.  
  1256. I get multiply defined symbols using templates
  1257. ==============================================
  1258.  
  1259.    You may be running into a bug that was introduced in version 2.6.1
  1260. (and is still present in 2.6.3) that generated external linkage for
  1261. templates even when neither `-fexternal-templates' nor
  1262. `-fno-implicit-templates' is specified.  There is a patch for this
  1263. problem at
  1264. `ftp://ftp.cygnus.com/pub/g++/gcc-2.6.3-template-fix'.
  1265.  
  1266.    I recommend either applying the patch or using
  1267. `-fno-implicit-templates' together with explicit template instantiation
  1268. as described in previous sections.
  1269.  
  1270.    This bug is fixed in 2.7.0.
  1271.  
  1272. Does g++ support the Standard Template Library?
  1273. ===============================================
  1274.  
  1275.    From Per Bothner:
  1276.  
  1277.    The Standard Template Library (STL) uses many of the extensions that
  1278. the ANSI/ISO committee has made to templates, and g++ doesn't support
  1279. some of these yet.  So if you grab HP's free implementation of STL it
  1280. isn't going to work.  However, libg++-2.6.2 contains a hacked version
  1281. of STL, based on work by Carsten Bormann, which permits gcc-2.6.3 to
  1282. compile at least the containers.  A full implementation is going to
  1283. need improved template support, which will take a while yet.
  1284.  
  1285.    As of libg++-2.7.0 and gcc-2.7.0, I've succeeded in making many short
  1286. STL example programs work, though there are still a number of bugs and
  1287. limitations.  Almost all of the ObjectSpace examples (a set of over 200
  1288. simple examples of STL usage) now work.
  1289.  
  1290.    There are several commercial suppliers of STL implementations;
  1291. ObjectSpace's version supports gcc-2.7.x.
  1292.  
  1293.    Mumit Khan has produced an "STL newbie guide" with lots of
  1294. information on using STL with gcc.  See
  1295.  
  1296.    `http://www.xraylith.wisc.edu/~khan/software/stl/STL.newbie.html'
  1297.  
  1298. What are the differences between g++ and the ARM specification of C++?
  1299. ======================================================================
  1300.  
  1301.    As of version 2.7.0, g++ has exception support on most but not all
  1302. platforms (no support on MIPS-based platforms yet), but it doesn't work
  1303. right if optimizaton is enabled, which means the exception
  1304. implementation is still not really ready for production use.
  1305.  
  1306.    Some features that the ANSI/ISO standardization committee has voted
  1307. in that don't appear in the ARM are supported, notably the `mutable'
  1308. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  1309. type `bool', with constants `true' and `false'.  The beginnings of
  1310. run-time type identification are present, so there are more reserved
  1311. words: `typeid', `static_cast', `reinterpret_cast', `const_cast', and
  1312. `dynamic_cast'.
  1313.  
  1314.    As with any beta-test compiler, there are bugs.  You can help improve
  1315. the compiler by submitting detailed bug reports.
  1316.  
  1317.    One of the weakest areas of g++ other than templates is the
  1318. resolution of overloaded functions and operators in complex cases.  The
  1319. usual symptom is that in a case where the ARM says that it is ambiguous
  1320. which function should be chosen, g++ chooses one (often the first one
  1321. declared).  This is usually not a problem when porting C++ code from
  1322. other compilers to g++, but shows up as errors when code developed under
  1323. g++ is ported to other compilers.  (I believe this is no longer a
  1324. significant problem in 2.7.0).
  1325.  
  1326.    [A full bug list would be very long indeed, so I won't put one here.
  1327. I may add a list of frequently-reported bugs and "non-bugs" like the
  1328. static class members issue mentioned above].
  1329.  
  1330. Will g++ compile InterViews?  The NIH class library?  Rogue Wave?
  1331. =================================================================
  1332.  
  1333.    The NIH class library uses a non-portable, compiler-dependent hack
  1334. to initialize itself, which makes life difficult for g++ users.  It
  1335. will not work without modification, and I don't know what modifications
  1336. are required or whether anyone has done them successfully.
  1337.  
  1338.    In short, it's not going to happen any time soon (previous FAQs
  1339. referred to patches that a new NIHCL release would hopefully contain,
  1340. but this hasn't happened).
  1341.  
  1342.    *Note:* I thought I saw an item indicating that someone *had*
  1343. patched NIHCL to work with g++.  Any pointers?
  1344.  
  1345.    I think that as of version 2.5.6, the standard g++ will compile the
  1346. standard 3.1 InterViews completely successfully.  Note that you'll need
  1347. the `-fno-for-scope' flag if you use gcc-2.7.0; with 2.7.2 you may be
  1348. able to omit this flag but you'll get warnings.
  1349.  
  1350.    According to Jason Merrill, the latest g++ (2.7.0) works with Rogue
  1351. Wave's `tools.h++' class library, but you may want to grab
  1352. `ftp://ftp.cygnus.com/pub/g++/Tools.h++-6.1-patch'.  Again, you'll need
  1353. the `-fno-for-scope' flag since Rogue Wave hasn't fixed their code to
  1354. comply with the new standard yet.
  1355.  
  1356. Debugging on SVR4 systems
  1357. =========================
  1358.  
  1359.    "How do I get debugging to work on my System V Release 4 system?"
  1360.  
  1361.    Most systems based on System V Release 4 (except Solaris) encode
  1362. symbolic debugging information in a format known as `DWARF'.
  1363.  
  1364.    Although the GNU C compiler already knows how to write out symbolic
  1365. debugging information in the DWARF format, the GNU C++ compiler does
  1366. not yet have this feature, nor is it likely to in the immediate future.
  1367.  
  1368.    Ron Guilmette has done a great deal of work to try to get the GNU
  1369. C++ compiler to produce DWARF format symbolic debugging information
  1370. (for C++ code) but he gave up on the project because of a lack of
  1371. funding and/or interest from the g++ user community.  If you have a
  1372. strong desire to see this project completed, contact Ron at
  1373. <rfg@netcom.com>.
  1374.  
  1375.    In the meantime, you *can* get g++ debugging under SVR4 systems by
  1376. configuring gcc with the `--with-stabs' option.  This causes gcc to use
  1377. an alternate debugging format, one more like that used under SunOS4.
  1378. You won't need to do anything special to GDB; it will always understand
  1379. the "stabs" format.
  1380.  
  1381. X11 conflicts with libg++ in definition of String
  1382. =================================================
  1383.  
  1384.    "X11 and Motif define String, and this conflicts with the String
  1385. class in libg++.  How can I use both together?"
  1386.  
  1387.    One possible method is the following:
  1388.  
  1389.      #define String XString
  1390.      #include <X11/Intrinsic.h>
  1391.      /* include other X11 and Motif headers */
  1392.      #undef String
  1393.  
  1394.    and remember to use the correct `String' or `XString' when you
  1395. declare things later.
  1396.  
  1397. Why can't I assign one stream to another?
  1398. =========================================
  1399.  
  1400.    [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  1401.  
  1402.    Assigning one stream to another seems like a reasonable thing to do,
  1403. but it's a bad idea.  Usually, this comes up because people want to
  1404. assign to `cout'.  This is poor style, especially for libraries, and is
  1405. contrary to good object-oriented design.  (Libraries that write directly
  1406. to `cout' are less flexible, modular, and object-oriented).
  1407.  
  1408.    The iostream classes do not allow assigning to arbitrary streams,
  1409. because this can violate typing:
  1410.  
  1411.      ifstream foo ("foo");
  1412.      istrstream str(...);
  1413.      foo = str;
  1414.      foo->close ();  /* Oops! Not defined for istrstream! */
  1415.  
  1416.    The original cfront implementation of iostreams by Jerry Schwarz
  1417. allows you to assign to `cin', `cout', `cerr', and `clog', but this is
  1418. not part of the draft standard for iostreams and generally isn't
  1419. considered a good idea, so standard-conforming code shouldn't use this
  1420. technique.
  1421.  
  1422.    The GNU implementation of iostream did not support assigning to
  1423. `cin', `cout', `cerr', and `clog' for quite a while, but it now does,
  1424. for backward compatibility with cfront iostream (versions 2.6.1 and
  1425. later of libg++).
  1426.  
  1427.    The ANSI/ISO C++ Working Paper does provide ways of changing the
  1428. streambuf associated with a stream.  Assignment isn't allowed; there is
  1429. an explicit named member that must be used.
  1430.  
  1431.    However, it is not wise to do this, and the results are confusing.
  1432. For example: `fstream::rdbuf' is supposed to return the *original*
  1433. filebuf, not the one you assigned. (This is not yet implemented in GNU
  1434. iostream.)  This must be so because `fstream::rdbuf' is defined to
  1435. return a `filebuf *'.
  1436.  
  1437. What are the rules for shipping code built with g++ and libg++?
  1438. ***************************************************************
  1439.  
  1440.    "Is it is possible to distribute programs for profit that are created
  1441. with g++ and use the g++ libraries?"
  1442.  
  1443.    I am not a lawyer, and this is not legal advice.  In any case, I have
  1444. little interest in telling people how to violate the spirit of the GNU
  1445. licenses without violating the letter.  This section tells you how to
  1446. comply with the intention of the GNU licenses as best I understand them.
  1447.  
  1448.    The FSF has no objection to your making money.  Its only interest is
  1449. that source code to their programs, and libraries, and to modified
  1450. versions of their programs and libraries, is always available.
  1451.  
  1452.    The short answer is that you do not need to release the source to
  1453. your program, but you can't just ship a stripped executable either,
  1454. unless you use only the subset of libg++ that includes the iostreams
  1455. classes (see discussion below) or the new libstdc++ library (available
  1456. in libg++ 2.6.2 and later).
  1457.  
  1458.    Compiling your code with a GNU compiler does not affect its
  1459. copyright; it is still yours.  However, in order to ship code that
  1460. links in a GNU library such as libg++ there are certain rules you must
  1461. follow.  The rules are described in the file COPYING.LIB that
  1462. accompanies gcc distributions; it is also included in the libg++
  1463. distribution.  See that file for the exact rules.  The agreement is
  1464. called the Library GNU Public License or LGPL.  It is much "looser"
  1465. than the GNU Public License, or GPL, that covers must GNU programs.
  1466.  
  1467.    Here's the deal: let's say that you use some version of libg++,
  1468. completely unchanged, in your software, and you want to ship only a
  1469. binary form of your code.  You can do this, but there are several
  1470. special requirements.  If you want to use libg++ but ship only object
  1471. code for your code, you have to ship source for libg++ (or ensure
  1472. somehow that your customer already has the source for the exact version
  1473. you are using), and ship your application in linkable form.  You cannot
  1474. forbid your customer from reverse-engineering or extending your program
  1475. by exploiting its linkable form.
  1476.  
  1477.    Furthermore, if you modify libg++ itself, you must provide source
  1478. for your modifications (making a derived class does not count as
  1479. modifying the library - that is "a work that uses the library").
  1480.  
  1481.    For certain portions of libg++ that implement required parts of the
  1482. C++ language (such as iostreams and other standard classes), the FSF has
  1483. loosened the copyright requirement still more by adding the "special
  1484. exception" clause, which reads as follows:
  1485.  
  1486.      As a special exception, if you link this library with files
  1487.      compiled with GCC to produce an executable, this does not cause
  1488.      the resulting executable to be covered by the GNU General Public
  1489.      License.  This exception does not however invalidate any other
  1490.      reasons why the executable file might be covered by the GNU
  1491.      General Public License.
  1492.  
  1493.    If your only use of libg++ uses code with this exception, you may
  1494. ship stripped executables or license your executables under different
  1495. conditions without fear of violating an FSF copyright.  It is the intent
  1496. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1497. draft standard are developed, these will also be placed under this
  1498. "special exception" license.  The code in the new libstdc++ library,
  1499. intended to implement standard classes as defined by ANSI/ISO, is also
  1500. licensed this way.
  1501.  
  1502.    To avoid coming under the influence of the LGPL, you can link with
  1503. `-liostream' rather than `-lg++' (for version 2.6.x and earlier), or
  1504. `-lstdc++' now that it is available.  In version 2.7.0 all the standard
  1505. classes are in `-lstdc++'; you can do the link step with `c++' instead
  1506. of `g++' to search only the `-lstdc++' library and avoid the LGPL'ed
  1507. code in `-lg++'.
  1508.  
  1509. -- 
  1510. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  1511.  
  1512. Work for something because it is good,
  1513. not just because it stands a chance to succeed.       -- Vaclav Havel
  1514.